﻿using Hrm.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AutoMapper.QueryableExtensions;

namespace Hrm.Services
{
    public class ApplicationService :BaseService<Application>, IApplicationService
    {
        IApplicationPermissionDbRepository _applicationPermissionDbRepository;

        public ApplicationService(IApplicationPermissionDbRepository applicationPermissionDbRepository)
            : base(applicationPermissionDbRepository)
        {
            this._applicationPermissionDbRepository = applicationPermissionDbRepository;
        }

        public IEnumerable<ApplicationDto> GetApplications()
        {
            var query = this.GetAllAbledAndOrderByCreatetime();
            return query.AsQueryable().Project().To<ApplicationDto>().ToList();
        }

        public PageResponse<ApplicationDto> GetPageList(PageRequest<ApplicationDto> request)
        {
            var query = this.GetAllAbledAndOrderByCreatetime().AsQueryable();
            if (!string.IsNullOrEmpty(request.filter.Name))
            {
                query = query.Where(p => p.Name.Contains(request.filter.Name));
            }
            var data = query.Project().To<ApplicationDto>();

            PageResponse<ApplicationDto> result = new PageResponse<ApplicationDto>(data, request.draw, request.start, request.length);
            return result;

        }
    }
}
